from keggapi import *
import javax
import string
import re

locator = KEGGLocator();
serv = locator.getKEGGPort();
#results = serv.get_genes_by_ko(args,"eco");
results = serv.bget("BR:ko03000")

regx = re.compile('[\>](K\w+)[\<\/a\>]')
X=[]
for m in regx.finditer(results):
	X += [m.group(1)]

X.reverse()
for ko in X:
	print 'ko:'+ko
	r = serv.get_genes_by_ko('ko:'+ko,'eco');
	try:
		gid = r[0].entry_id
		print gid
	except:
		pass